import Vue from 'vue'
import Router from 'vue-router'
/* Layout */
import Layout from '../views/layout/Layout'
const _import = require('./_import_' + process.env.NODE_ENV)

Vue.use(Router)
let path = ''
// if (process.env.NODE_ENV !== 'development') {
//   path = '/qianduan'
// }
export const commonRoutes = [
	{ // 首页部分
		path: path + '',
		component: Layout,
		children: [
			{
				path: '',
				component: _import('index/index'),
				meta: { title: '首页', name: 'index' }
			}
		]
	},
	// 登录
	{
		path: path + '/login/index',
		component: _import('login/index'),
		meta: { title: '登录' },
		name: 'login'
	}
]
export const routesMap = [
	// 系统管理台
	{
		path: path + '/system',
		component: Layout,
		name: 'system',
		roles: '1',
		children: [
			{
				path: '/system/account',
				component: _import('system/accountIndex'),
				meta: { title: '账号管理', name: 'system' }
			}
		]
	},
	// 运营管理
	{
		path: path + '/operation',
		component: Layout,
		name: 'operation',
		roles: '13',
		children: [
			{
				path: '/operation/index',
				component: _import('operation/operateIndex'),
				meta: { title: 'ICD数据配置', name: 'operation' }
			}
		]
	},
	// 机构管理
	{
		path: path + '/institution',
		component: Layout,
		name: 'institution',
		roles: '2',
		children: [
			{
				path: '/institution/index',
				component: _import('institution/institutionIndex'),
				meta: { title: '机构设置', name: 'institution' }
			}
		]
	},
	// 支付订单
	{
		path: path + '/order',
		component: Layout,
		name: 'order',
		roles: '15',
		children: [
			{
				path: '/order/index',
				component: _import('order/orderIndex'),
				meta: { title: '支付订单', name: 'order' }
			},
			{
				path: '/order/note',
				component: _import('order/orderNote'),
				meta: { title: '短信充值', name: 'order' }
			}
		]
	},
	// 客服
	{
		path: path + '/service',
		component: Layout,
		name: 'service',
		roles: '16',
		children: [
			{
				path: '/service/index',
				component: _import('service/serviceIndex'),
				meta: { title: '客服', name: 'service' }
			}
		]
	}
]

const router = new Router({
  mode: 'history',
  routes: commonRoutes
})

// var _hmt = window._hmt || []

router.beforeEach((to, from, next) => {
  if (to.meta.title) { // 如果设置标题，拦截后设置标题
    document.title = to.meta.title
  }

  // var _hmt = [];
  // (function() {
  //   var hm = document.createElement('script')
  //   hm.src = 'https://hm.baidu.com/hm.js?2f09dd62369eb852fe48bdb15d95358c'
  //   var s = document.getElementsByTagName('script')[0]
  //   s.parentNode.insertBefore(hm, s)
  // }
  // )()
  // _hmt.push(['_trackPageview', '' + to.fullPath])

  next()
})

export default router
